﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Data;
using System.Data.SqlClient;


namespace DA
{
    public class tiepnhanhocsinh_DA
    {
        DataLINQHocSinhDataContext db = new DataLINQHocSinhDataContext();        
        QUYDINH qd = new QUYDINH();
        public List<HOCSINH> layall()
        {
            return db.HOCSINHs.ToList();
        }
        public object Laytheomalop(string ml)
        {
            return db.HOCSINHs.Where(p => p.MALOP == ml).ToList();
        }
        public List<LOP> LayTheoML()
        {
            return db.LOPs.ToList();
        }
        public bool KiemTraTuoi(int qd)
        {
            var query = from p in db.QUYDINHs
                        where p.TUOITHAPNHAT >= qd && p.TUOICAONHAT <= qd
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }
        public bool KiemTraSiSo(int qd)
        {
            var query = from p in db.QUYDINHs
                        where p.SISOTOIDA > qd
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }
        public bool ktrahocsinh(HOCSINH hs)
        {
            var query = from p in db.MONHOCs
                        where p.MAMH == hs.MAHS
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }
        public void tiepnhanhocsinh_add(string mahs, string tenhs, string email, bool gioitinh, DateTime ngaysinh, string diachi, string malop)
        {
            HOCSINH hs = new HOCSINH();
            hs.MAHS = mahs;
            hs.TENHS = tenhs;
            hs.EMAIL = email;
            hs.GIOITINH = gioitinh;
            hs.NGAYSINH = ngaysinh;
            hs.DIACHI = diachi;
            hs.MALOP = malop;
            db.HOCSINHs.InsertOnSubmit(hs);
            db.SubmitChanges();
        }
        public int tuoi(int kt)
        {
            int tuoikt = 0;
            var query = from p in db.QUYDINHs
                        select p;
            foreach (var item in query)
            {
                if (kt == 1)
                {
                    tuoikt = item.TUOICAONHAT.Value;
                }
                else
                {
                    tuoikt = item.TUOITHAPNHAT.Value;
                }
            }
            return tuoikt;
        }
    }
}

